<template>
  <div>
    <p ref="test">测试值</p>

    <ComponentsRefChild ref="refTest"></ComponentsRefChild>
    <button @click="printMsg">打印测试值</button>
    <button @click="printChildMsg">打印子组件的值</button>
  </div>

</template>


<script setup>
import ComponentsRefChild from './components/ComponentsRefChild.vue';
import { onMounted, ref } from 'vue'
const test = ref(null)
const refTest = ref(null)

const printMsg = () => {
  console.log(test.value)
}

// 通过ref可以使用到相应组件中通过defineExpose出来的 方法/变量/常量
const printChildMsg = () => {
  console.log('printChildMsg:', refTest.value.refMsg)
  refTest.value.logRefMsg()
}

onMounted(() => {
  console.log(test.value)
})

</script>

<style scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 20px;
}

.my-button {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
  padding: 15px 32px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 400;
}
</style>
